<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
//JHtml::_('behavior.tooltip');
JPluginHelper::importPlugin('content');
$dispatcher	= JDispatcher::getInstance();
if (!class_exists('plgContentLightShop')) {
	JError::raiseWarning(50, str_rot13('WYVO_FUBC_REEBE_YBNQ_CYHTVA'));
}
?>
<?php if($this->carts):?>
<link rel="stylesheet" href="<?php echo JURI::root().'components/com_shop/assets/'; ?>cart.css" type="text/css" />
<form action="<?php echo JRoute::_('index.php?option=com_shop&task=cart.complete'); ?>" method="post" enctype="multipart/form-data" class="shop-orcer" id="shop-order">
<table  class="viewcart" width="100%" cellpadding="0" cellspacing="0">
<thead>	<tr><td colspan="5"><div class="title_cart"><?php echo JText::_('VIEW CART'); ?></div></td></tr></thead>
<tbody>
	<tr>
    	<td class="title_cart_product"><?php echo JText::_('PICTURE'); ?></td><td class="title_cart_product"><?php echo JText::_('PRODUCT'); ?></td><td class="title_cart_product"><?php echo JText::_('PRICE'); ?></td><td class="title_cart_product"><?php echo JText::_('QUANTITY'); ?></td><td class="title_cart_product"><?php echo JText::_('TOTAL PRICE'); ?></td>
    </tr>
    <?php foreach($this->carts as $cart):?>
    <tr>
    	<td align="center">
        	<a href="<?php echo JRoute::_('index.php?option=com_shop&view=detail&id='.$cart['id'].':'.$cart['alias']); ?>" target="_blank"><img src="<?php echo $this->path_img.$cart['image']; ?>" title="<?php echo $cart['title']; ?>" width="100" height="100" class="shop-cart-imgage" /></a>
        </td>
        <td class="shop-title-product-view-cart">
        <a href="<?php echo JRoute::_('index.php?option=com_shop&view=detail&id='.$cart['id'].':'.$cart['alias']); ?>" target="_blank"><?php echo $cart['title']; ?></a>
        </td>
        <td class="shop-price-product-view-cart">
        <?php $dispatcher->trigger('onFormatPrice',array($cart['price'],$cart['currency'],&$price)); echo $price; ?>
        </td>
       <td class="shop-quantity-product-view-cart">
        <?php echo $cart['quantity']; ?>
        </td>
       <td class="shop-total-price-view-cart">
<?php $dispatcher->trigger('onFormatPrice',array($cart['price']*$cart['quantity'],$cart['currency'],&$price)); echo $price; ?>
        </td>
    </tr>
    <?php endforeach;?>
</tbody>
<tfoot>
<tr>
	<td colspan="5">
<?php 
$total = 0;
$currency = '';
foreach($this->carts as $cart){
	$total +=$cart['price']*$cart['quantity'];
	$currency = $cart['currency'];
}


?>
    <div class="shop-button-total">
    	<div class="shop-button-total-text"><span class="shop-bt-tt-sp"><?php echo JText::_('TOTAL PRICE'); ?></span><?php $dispatcher->trigger('onFormatPrice',array($total,$currency,&$total)); echo $total; ?></div>
    </div>
    </td>
</tr>
</tfoot>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="shop-infomation-customer">
<thead>
<tr>
<td colspan="2">
	<div class="shop-information-title"><?php echo JText::_('ADD INFOMATION CUSTOMER'); ?></div>
</td>
</tr>
</thead>
<tbody>
	<tr>
    	<td width="20%" class="shop-information-label"><label for="username"><?php echo JText::_('INPUT NAME'); ?></label></td>
        <td><input type="text" id="username" name="username" value="" size="50" placeholder="<?php echo JText::_('ADD USERNAME'); ?>" /></td>
    </tr>
    <tr>
    	<td  class="shop-information-label"><label for="email"><?php echo JText::_('INPUT EMAIL'); ?></label></td>
        <td><input type="email" id="email" name="email" value="" size="50" placeholder="<?php echo JText::_('ADD EMAIL'); ?>" /></td>
    </tr>
    <tr>
    	<td  class="shop-information-label"><label for="phone"><?php echo JText::_('INPUT PHONE'); ?></label></td>
        <td><input type="text" id="phone" name="phone" value=""  size="50" placeholder="<?php echo JText::_('ADD PHONE'); ?>"/></td>
    </tr>
     <tr>
    	<td  class="shop-information-label"><label for="province"><?php echo JText::_('SELECT PROVINCE'); ?></label></td>
        <td>
<?php 
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__shop_address');
$query->where('state = 1');
$query->where('parent_id = 0');
$db->setQuery((string)$query);
$provinces = $db->loadObjectList();
$dis = 0;
?>
<select name="province" id="province" class="shop-infomation-province" onchange="onChangeProvince(this.value);">
<?php foreach($provinces as $item):?>
<option value="<?php echo $item->id; ?>" <?php if($item->active == 1): $dis = $item->id; ?> selected="selected"<?php endif;?> ><?php echo $item->title; ?></option>
<?php endforeach; ?>
</select>
        </td>
    </tr>
    <tr>
    	<td  class="shop-information-label"><label for="district"><?php echo JText::_('SELECT DISTRICT'); ?></label></td>
        <td>
<?php 
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__shop_address');
$query->where('state = 1');
$query->where('parent_id = '.$dis);
$db->setQuery((string)$query);
$districts = $db->loadObjectList();
$dis = 0;
?>
<select name="district" id="district" class="shop-infomation-district">
<?php foreach($districts as $item):?>
<option value="<?php echo $item->id; ?>" <?php if($item->active == 1): $dis = $item->id; ?> selected="selected"<?php endif;?> ><?php echo $item->title; ?></option>
<?php endforeach; ?>
</select>
        </td>
    </tr>
    <tr>
    	<td  class="shop-information-label"><label for="address"><?php echo JText::_('INPUT ADDRESS'); ?></label></td>
        <td><textarea name="address" id="address" rows="3" cols="50" placeholder="<?php echo JText::_('ADD ADDRESS'); ?>"></textarea></td>
    </tr>
</tbody>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="shop-infomation-method">
<thead>
<tr>
<td colspan="2">
	<div class="shop-information-method-title"><?php echo JText::_('ADD INFOMATION METHOD'); ?></div>
</td>
</tr>
</thead>
<tbody>
<tr>
	<td><label for="method"><?php echo JText::_('SELECT METHOD'); ?></label></td>
    <td>
<?php 
$query->clear();
$query->select('*');
$query->from('#__shop_method');
$query->where('state = 1');
$db->setQuery((string)$query);
$methods = $db->loadObjectList();
?>
<select name="method" onchange="onChangeMethod(this.value);">
<option value="">----->   <?php echo JText::_('SELECT METHOD PAID'); ?>   <-----</option>
<?php foreach($methods as $item):?>
<option value="<?php echo $item->id; ?>"><?php echo $item->title; ?></option>
<?php endforeach;?>
</select>
    </td>
</tr>
</tbody>
<tfoot><tr><td colspan="2"><div id="selectmethodpaid"><?php echo JText::_('YOU NOT SELECT METHOD PAID'); ?></div></td></tr></tfoot>
</table>
<div class="shop-button-next-prev">
<div class="shop-button-prev-lft"><a href="<?php echo JRoute::_('index.php?option=com_shop&view=cart&layout=default'); ?>" title="<?php echo JText::_('BACK SHOP VIEW CART'); ?>" class="shop-button-prev"><?php echo JText::_('BACK VIEW CART'); ?></a></div>
<div class="shop-button-prev-rgt"><a href="javascript::" onclick="completesubmit();" rel="nofollow" title="<?php echo JText::_('COMPLETE ORDER'); ?>" class="shop-button-prev"><?php echo JText::_('COMPLETE ORDER'); ?></a></div>
</div>
</form>

<script type="text/javascript">
function validateEmail(id) { var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; return emailPattern.test(id); } 
function completesubmit(){	var $doc = document.getElementById('shop-order'); 
if($doc.username.value == ''){
alert('<?php echo JText::_('ADD USERNAME ORDER CONTACT'); ?>');
$doc.username.focus();
return false;
}else if(validateEmail($doc.email.value) == false){
alert('<?php echo JText::_('ADD EMAIL ORDER CONTACT'); ?>');
$doc.email.focus();
return false;
}else if($doc.phone.value == ''){
alert('<?php echo JText::_('ADD PHONE ORDER CONTACT');?>');
$doc.phone.focus();
return false;
}else if($doc.method.value == ''){
alert('<?php echo JText::_('SELECT METHOD'); ?>');
$doc.method.focus();
return false;
}else{
$doc.submit();
}
}
function onChangeProvince($id){
jQuery.ajax({  type: "POST",  url: "<?php echo JRoute::_('index.php?option=com_shop&view=process&type=loadaddress&id=01678877116'); ?>",  data: "idprovince="+$id,	success: function(msg) { jQuery('#district').html(msg); }}); }

function onChangeMethod($id){
jQuery.ajax({  type: "POST",  url: "<?php echo JRoute::_('index.php?option=com_shop&view=process&type=loadmethod&id=01678877116'); ?>",  data: "idmethod="+$id,	success: function(html) { jQuery('#selectmethodpaid').html(html); }}); }
</script>
<?php endif;?>